package com.lanou.dllo.mynovel.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.android.volley.RequestQueue;
import com.android.volley.toolbox.Volley;
import com.lanou.dllo.mynovel.R;
import com.lanou.dllo.mynovel.bean.StoreSeek;

import java.util.List;

/**
 * Created by dllo on 15/11/4.
 */
public class StoreSeekAdapter extends
        RecyclerView.Adapter<StoreSeekAdapter.StoreSeekHodler>{

    private List<StoreSeek.DataEntity.ReturnDataEntity> returnData;
//    private RequestQueue requestQueue;
//
//    // 在此方法内初始化请求队列
//    public StoreSeekAdapter(Context context) {
//        // 初始化请求队列
//        requestQueue = Volley.newRequestQueue(context);
//    }

    public void addData(List<StoreSeek.DataEntity.ReturnDataEntity> datas) {
        returnData = datas;
        notifyDataSetChanged(); // 改变数据 通知刷新
    }

    public class StoreSeekHodler extends RecyclerView.ViewHolder {

        private TextView tag;

        public StoreSeekHodler(View itemView) {
            super(itemView);

            tag = (TextView) itemView.findViewById(R.id.tag);
        }
    }

    @Override
    public StoreSeekHodler onCreateViewHolder(ViewGroup parent, int viewType) {
        // 获得布局加载器
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        // 加载行布局文件
        View view = inflater.inflate(R.layout.fragment_storeseek_content, null);
        // 构建组件缓存对象并返回
        return new StoreSeekHodler(view);
    }

    @Override
    public void onBindViewHolder(StoreSeekHodler holder, int position) {
        if (returnData != null && returnData.size() > 0) {
            StoreSeek.DataEntity.ReturnDataEntity entity = returnData.get(position);
            // 设置数据
            holder.tag.setText(entity.getTag());
            holder.tag.setBackgroundColor(Color.parseColor(entity.getBgColor()));
        }
    }

    @Override
    public int getItemCount() {
        return returnData != null && returnData.size() > 0 ? returnData.size() : 0;
    }
}
